package com.example.springmultipledatasourcesample;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class JPADataSourceConfig {

    @Primary
    @Bean(name = "carDataSource")
    @Qualifier("carDataSource")
    @ConfigurationProperties(prefix="spring.datasource.car")   //结合application.yml的配置
    public DataSource carDataSource() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "userDataSource")
    @Qualifier("userDataSource")
    @ConfigurationProperties(prefix="spring.datasource.user")    //结合application.yml的配置
    public DataSource userDataSource() {
        return DataSourceBuilder.create().build();
    }

}
